Skip to content

Conversation

@ressys1978
Copy link

@ressys1978 ressys1978 commented Oct 15, 2025

Describe your changes

Introduced the NETBIRD_IDP_TIMEOUT environment variable to the management service. This allows configuring a timeout for supported IDPs. If the variable is unset or contains an invalid value, a default timeout of 10 seconds is used as a fallback.

This is needed for larger IDP environments where 10s is just not enough time.

Issue ticket number and link

This should fix #1386

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

I don't feel this needs to be documented at this time, as currently the number of self-hosted netbird users with larger IDP environments is probably very small.

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

Summary by CodeRabbit

  • New Features
    • IDP authentication timeouts are now configurable via environment variable, enabling flexible adjustment of request deadlines for identity provider integrations instead of a fixed timeout.

@ressys1978 ressys1978 changed the title {management Add idp timeout env variable [management] Add idp timeout env variable Oct 15, 2025
@ressys1978
Copy link
Author

@mlsmaycon how does one get this reviewed?

@mlsmaycon
Copy link
Collaborator

@bcmmbaga can you have a look?

@ressys1978 ressys1978 requested a review from mlsmaycon October 24, 2025 11:29
@bcmmbaga bcmmbaga self-requested a review October 28, 2025 12:55
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 17, 2025

Walkthrough

Introduces environment-variable-driven timeout configuration for IDP HTTP clients across all manager implementations. Replaces hardcoded 10-second timeouts with a dynamic idpTimeout() function that reads NB_IDP_TIMEOUT environment variable, defaulting to 10 seconds on absence or parse error.

Changes

Cohort / File(s) Summary
Timeout Configuration Infrastructure
management/server/idp/util.go
Added idpTimeout() helper function that reads NB_IDP_TIMEOUT environment variable with 10-second default. Introduced unexported constants idpTimeoutEnv and defaultTimeout. Extended imports to include os package.
IDP Manager HTTP Client Updates
management/server/idp/auth0.go, management/server/idp/authentik.go, management/server/idp/azure.go, management/server/idp/google_workspace.go, management/server/idp/jumpcloud.go, management/server/idp/keycloak.go, management/server/idp/okta.go, management/server/idp/pocketid.go, management/server/idp/zitadel.go
Replaced fixed 10-second HTTP client timeout with dynamic idpTimeout() call in each manager's initialization function. Removed unused time imports from google_workspace.go, jumpcloud.go, okta.go, and pocketid.go. Minor formatting adjustments in authentik.go and zitadel.go.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • The changes follow a consistent, homogeneous pattern across all IDP managers—direct substitution of timeout source with minimal logic variance.
  • Primary focus: verify idpTimeout() correctly handles environment variable parsing and fallback to default; ensure consistent application across all nine manager files.
  • Minor formatting changes in authentik.go (single-line signature) and zitadel.go (blank line addition) are non-functional and can be quickly verified.

Poem

🐰 A Timeout's Tale

Ten seconds was rigid, now flexible and free,
Through environment whispers, the timeout shall be.
Each IDP manager, now nimble and keen,
Respects the duration that's set in between.
Keycloak's federation no longer will weep! 🌳

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: introducing an IDP timeout environment variable for the management service.
Description check ✅ Passed The description follows the template with all required sections completed: changes described, issue linked, checklist items marked appropriately, and documentation decision explained.
Linked Issues check ✅ Passed The PR addresses the core requirement from issue #1386 by introducing a configurable IDP timeout environment variable that allows larger IDP environments to override the default 10-second timeout.
Out of Scope Changes check ✅ Passed All changes are focused on implementing the IDP timeout feature across eight IDP manager files and one utility file; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link

@ressys1978 ressys1978 requested a review from bcmmbaga November 17, 2025 13:37
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
management/server/idp/pocketid.go (1)

89-93: Consider consistent formatting across all IDP implementations.

Some IDP files (okta.go, jumpcloud.go) don't have the extra blank line after httpClient initialization, while others do (azure.go, zitadel.go, google_workspace.go, keycloak.go, auth0.go, pocketid.go). Consider applying uniform formatting for consistency.

management/server/idp/util.go (1)

82-94: Core implementation is correct, but consider adding logging for parse errors.

The function correctly reads the environment variable and falls back to the default timeout when unset or unparseable. However, when time.ParseDuration fails, the function silently returns the default without logging. This could make debugging difficult if someone sets an invalid value.

Consider adding a log warning when parse fails:

 func idpTimeout() time.Duration {
 	timeoutStr, ok := os.LookupEnv(idpTimeoutEnv)
 	if !ok || timeoutStr == "" {
 		return defaultTimeout
 	}
 
 	timeout, err := time.ParseDuration(timeoutStr)
 	if err != nil {
+		log.Warnf("invalid %s value %q, using default %s: %v", idpTimeoutEnv, timeoutStr, defaultTimeout, err)
 		return defaultTimeout
 	}
 	return timeout
 }

Note: You'll need to import the log package at the top of the file:

log "github.com/sirupsen/logrus"
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd9a867 and 5a40b42.

📒 Files selected for processing (10)
  • management/server/idp/auth0.go (1 hunks)
  • management/server/idp/authentik.go (1 hunks)
  • management/server/idp/azure.go (1 hunks)
  • management/server/idp/google_workspace.go (1 hunks)
  • management/server/idp/jumpcloud.go (1 hunks)
  • management/server/idp/keycloak.go (1 hunks)
  • management/server/idp/okta.go (1 hunks)
  • management/server/idp/pocketid.go (1 hunks)
  • management/server/idp/util.go (2 hunks)
  • management/server/idp/zitadel.go (1 hunks)
🔇 Additional comments (11)
management/server/idp/jumpcloud.go (1)

47-51: LGTM!

The timeout configuration change is consistent with the broader IDP timeout refactoring.

management/server/idp/zitadel.go (1)

166-170: LGTM!

The dynamic timeout configuration is correctly applied while preserving the existing transport configuration.

management/server/idp/azure.go (1)

60-64: LGTM!

The timeout configuration aligns with the centralized IDP timeout management approach.

management/server/idp/google_workspace.go (1)

50-54: LGTM!

The dynamic timeout implementation is correctly integrated into the Google Workspace manager initialization.

management/server/idp/keycloak.go (1)

65-69: LGTM! Directly addresses the reported Keycloak timeout issue.

This change enables users to configure longer timeouts for large Keycloak environments with LDAP federation, resolving the "context deadline exceeded" errors reported in issue #1386.

management/server/idp/auth0.go (1)

138-142: LGTM!

The timeout configuration change is properly integrated into the Auth0 manager initialization.

management/server/idp/pocketid.go (1)

89-93: LGTM!

The timeout configuration is consistently applied.

management/server/idp/okta.go (1)

46-49: ✓ Verification complete—idpTimeout() implementation is correct and properly handles errors.

The function exists in management/server/idp/util.go (lines 83–94) and:

  • Reads the environment variable NB_IDP_TIMEOUT
  • Returns a default timeout of 10 seconds if the env var is missing, empty, or contains an invalid duration format
  • Includes proper error handling with fallback behavior

The idpTimeout() call in the okta.go changes is sound.

management/server/idp/authentik.go (1)

51-59: LGTM! Timeout now configurable via environment variable.

The change from hardcoded 10 * time.Second to idpTimeout() successfully makes the HTTP client timeout configurable through the NB_IDP_TIMEOUT environment variable, addressing the issue with large Keycloak setups that may require longer timeouts.

management/server/idp/util.go (2)

7-9: LGTM! Necessary imports for environment-driven timeout.

The os and time imports are correctly added to support the new idpTimeout() functionality.


75-80: LGTM! Constants follow review feedback.

The constants correctly implement the suggestions from previous reviews: using the NB_ prefix for consistency and defining defaultTimeout as a constant to avoid re-parsing.

@smartmanru
Copy link

smartmanru commented Nov 18, 2025

how soon will this fix appear in the main branch?
@mlsmaycon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keycloak idp timeout

8 participants